<template>
  <div class="home">
    <!-- 
      <el-container>：外层容器。当子元素中包含 <el-header> 或 <el-footer> 时，全部子元素会垂直上下排列，否则会水平左右排列。
      <el-header>：顶栏容器。
      <el-aside>：侧边栏容器。
      <el-main>：主要区域容器。
      <el-footer>：底栏容器。
    -->
    <el-container>
      <el-aside width="200px">
        <router-link to="/" class="logo">
          <img src="../assets/timg1.gif" />
        </router-link>
        <!-- 侧边栏容器 -->
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#000"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened="true"
          :router="true"
        >
          <el-menu-item index="/">
            <i class="el-icon-s-home"></i>
            <span>首页</span>
          </el-menu-item>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="1-1">
                <i class="el-icon-user-solid"></i>
                <span> 用户列表</span>
              </el-menu-item>
              <el-menu-item index="1-2">
                <i class="el-icon-user-solid"></i>
                <span>用户添加</span>
              </el-menu-item>
              <el-menu-item index="/login">
                <i class="el-icon-circle-plus"></i>
                <span>用户添加</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>文章管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/home/post_list">
                <i class="el-icon-user-solid"></i>
                <span>文章列表</span>
              </el-menu-item>
              <el-menu-item index="/home/post_publish">
                <i class="el-icon-circle-plus"></i>
                <span>文章添加</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>栏目管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="3-1">
                <i class="el-icon-user-solid"></i>
                <span>栏目列表</span>
              </el-menu-item>
              <el-menu-item index="3-2">
                <i class="el-icon-circle-plus"></i>
                <span>栏目添加</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
        <!--  -->
      </el-aside>
      <el-container>
        <el-header height="80px">
          <img :size="50" class="avatar" :src="userinfo.head_img | imgUrl" />
          <span class="nickname">欢迎你：{{ userinfo.nickname }}</span>
          <el-button type="danger">退出</el-button>
        </el-header>
        <el-main>
          <!-- 主要区域容器 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getUserInfoAPI } from "../api/user";
import { getUserId } from "../utils/localData";
export default {
  data() {
    return {
      userinfo: {},
    };
  },
  async created() {
    // 获取用户 id，发送请求的时候需要用到
    const id = getUserId();
    // console.log(id);
    // 获取用户信息
    const res = await getUserInfoAPI(id);
    // console.log(res);
    // 把用户信息绑定到页面中
    this.userinfo = res.data.data;
  },
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100vh;
}
.el-header {
  background-color: #333;
  color: #fff;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .nickname {
    margin: 0 10px;
  }
}
.el-aside {
  background-color: #000;
  color: #fff;
  .logo {
    width: 100%;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 80px;
  }
}
.el-main {
  background-color: #e9eef3;
  color: #333;
}
</style>